import Vue from 'vue';
import Loading from './ch-showLoading.vue';

const LoadingConstructor = Vue.extend(Loading); //注册实例
let instance = null;
/**
 * @description 加载动画
 * @param {object} options
 *  @property {boolean} show = [true|false] - 是否展示
 */
const ShowLoading = (options = {}) => {
	if(options.show){
		if(instance == null){
			instance = new LoadingConstructor({
				data: options,//数据
			}).$mount();//挂载实例
			document.body.appendChild(instance.$el);
		}else{
			instance.load()
		}
	}else{
		if(instance != null){
			instance.close()
		}
	}
}

export default ShowLoading